<?php
	require_once('tools/header.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery.min.js"></script>
<!-- Custom Theme files -->
<!--theme-style-->
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />	
<!--//theme-style-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Whizz Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!--flexslider-->
<link rel="stylesheet" href="css/flexslider.css" type="text/css" media="screen" />
<!--//flexslider-->
	<style>
		.pageStyle li{
			float: left;
		}
	</style>
</head>
<body>
<!--header-->
<div class="header">
	<div class="container">
		<div class="header-top">
		<div class="top-nav">
			<span class="menu"><img src="images/menu.png" alt=""> </span>
				<ul>
					<li ><a href="index.php" class="color"><i class="glyphicon glyphicon-home"></i>  </a> </li>
					<li><a href="portfolio.php"   class="hvr-bounce-to-top">分类照片</a></li>
<!--					<li ><a href="404.php" class="hvr-bounce-to-top">暂定 </a> </li>-->
					<li><a href="blog.php"  class="hvr-bounce-to-top">博客 </a></li>
					<li><a href="about.php"  class="hvr-bounce-to-top">关于我 </a></li>
					<!--					<li><a href="typo.php"  class="hvr-bounce-to-top">Typo </a></li>-->
					<li><a href="contact.php"  class="hvr-bounce-to-top">联系我 </a></li>
				<div class="clearfix"> </div>
				</ul>
					<!--script-->
				<script>
					$("span.menu").click(function(){
						$(".top-nav ul").slideToggle(500, function(){
						});
					});
			</script>	
		</div>
		 <div class="search-in" >

		</div>
			<script type="text/javascript">
				$('.search').hide();
				$('button').click(function (){
				$('.search').show();
				$('.text').focus();
				}
				);
				$('.close-in').click(function(){
				$('.search').hide();
				});
			</script>
			<div class="clearfix"> </div>
		</div>
		<div class="logo">
			<a href="index.php"><img src="images/logo.png" alt="">	</a>
		</div>
	</div>
</div>
<!--//header-->
<!--content-->
<div class="blog">
	<div class="container">
		<h1>Blog</h1>
		<div class="blog-head">
			<?php
				// 每页显示文章数量
				$pagesize = 6;

				$sql2 = "select count(*) as total from article";
				$stmt2 = $db->prepare($sql2);
				$stmt2->execute();

				$result2 = $stmt2->fetch(PDO::FETCH_ASSOC);
				$total = $result2['total'];

				// 总页数
				$pages = ceil($total / $pagesize);

				// 设置页数
				if(isset($_GET['page'])){
					$page = $_GET['page'];
				}else{
					$page = 1;
				}

				// 记录偏移量
				$offset = $pagesize * ($page - 1);


				$sql = "select * from article order by article_date desc limit ? offset ?";
				$stmt = $db->prepare($sql);
				$stmt->bindValue(1, $pagesize, PDO::PARAM_INT);
				$stmt->bindValue(2, $offset, PDO::PARAM_INT);
				$stmt->execute();

				$result = $stmt->fetchAll(PDO::FETCH_BOTH);

				for($i = 0; $i < sizeof($result); $i++){
			?>
				<div class="col-md-4 blog-top">
					<div class="blog-in">
						<a href="single.php?id=<?=$result[$i][0]?>">

<!--							文章包含的第一张照片-->
							<?php
								$pic = $result[$i][4];
//								echo $pic;
								$picArr = explode(';', $pic);
//								print_r($picArr);
								$picUrl = 'articlePictures/'.$picArr[0];
							?>
							<img style="width: 600px; height: 230px" class="img-responsive" src="<?=$picUrl?>" alt=" ">
						</a>

						<div class="blog-grid">
<!--							 文章标题-->
							<h3><a href="single.php?id=<?=$result[$i][0]?>"><?=$result[$i][1]?></a></h3>

<!--							文章部分正文-->
							<p>
								<?php
								$str = mb_substr($result[$i][5], 0, 180);
								echo $str;
								?>
							</p>

<!--							 发布日期-->
							<div class="date">
								<span class="date-in"><i class="glyphicon glyphicon-calendar"> </i>
									<?php
										$date = substr($result[$i][2], 0, 9);
										echo $date;
									?>
								</span>

<!--								 评论留言数-->
								<a href="single.php" class="comments"><i class="glyphicon glyphicon-comment"></i>
									<?php
										$sql3 = "select count(*) as total2 from comments where article_id = ?";
										$stmt3 = $db->prepare($sql3);
										$stmt3->bindValue(1, $result[$i][0]);
										$stmt3->execute();

										$result3 = $stmt3->fetch(PDO::FETCH_ASSOC);
										$total2 = $result3['total2'];

										echo $total2;
									?>
								</a>
								<div class="clearfix"> </div>
							</div>
							<a href="single.php?id=<?=$result[$i][0]?>"class="hvr-overline-from-center more">READ MORE</a>
						</div>
					</div>
				</div>
			<?php
				}
			?>
			<div class="clearfix"> </div>

<!--			 分页显示区域-->
			<div style="margin-top: 30px; margin-left: 20px">
				<ul style="list-style: none" class="pageStyle">
					<?php
						$first = 1;
						$prev = $page - 1;
						$next = $page + 1;
						$last = $pages;

						echo('<li><a href="#">共 '.$pages.' 页&nbsp;&nbsp;</a></li>');

						if($page > 1){
							echo('<li><a href="blog.php?page='.$first.'" >首页&nbsp;&nbsp;</a></li>');
							echo('<li><a href="blog.php?page='.$prev.'" >上一页&nbsp;&nbsp;</a></li>');
						}

						if($pages > 1){
								for($p = 1; $p <= $pages; $p++){
									if($p == $page){
										echo('<li><a href="#">[ '.$p.' ]&nbsp;&nbsp;</a></li>');
									}else{
										echo('<li><a href="blog.php?page='.$p.'">'.$p.'&nbsp;&nbsp;</a></li>');
									}
								}
							}

						if($page <$pages){
							echo '<li><a href="blog.php?page='.$next.'">下一页&nbsp;&nbsp;</a></li>';
							echo '<li><a href="blog.php?page='.$last.'">末页&nbsp;&nbsp;</a></li>';
						}
					?>
				</ul>
			</div>
		</div>
	</div>
</div>
<!--//content-->
<div class="footer">
		<div class="container">
				<div class="footer-class">
				<div class="col-md-10 class-footer">
					<ul>
						<li ><a href="index.php" >首页</a> </li>
						<li><a href="portfolio.php" >分类照片</a></li>
						<!--						<li ><a href="404.php" >Tours </a> </li>-->
						<li><a href="blog.php" >博客 </a></li>
						<li><a href="about.php" >关于我 </a></li>
						<!--						<li><a href="typo.php" >Typo </a></li>-->
						<li><a href="contact.php" >联系我 </a></li>
						<li><a href="tools/doAction.php?action=checkCookies" >进入后台管理 </a></li>
					</ul>
					<p class="footer-grid">Copyright &copy; 2017.Company name All rights reserved.</p>
				</div>	
				<div class="col-md-2"> 
					 <ul class="social">
						<li ><a href="#"><i> </i></a></li>
						<li ><a href="#"><i class="facebook"> </i></a></li>
						<li ><a href="#"><i class="google"> </i></a></li>
					</ul>
				</div>
				<div class="clearfix"> </div>
			 	</div>
		 </div>
		
	</div>
</body>
</html>